trigger CXGFetchTaskOwnerManager on Task (before Insert,before Update) {

    //Trigger Name:CXGFetchTaskOwnerManager
    //Date:3rd August 2011  
    //Author:Manish Tiwari/Accenture  
    //Requirement/Project Name:CXG 
    //Requirement/Project Description:The Triggers fire on Insert or Update .It Updates the Onwer's Manager Name On Task.
  
    Set<Id> user_id = new Set<Id>();
    ID CxGTaskRecordTypeID = RecordTypeHelper.GetRecordTypeIdByDevName('Task', 'CXG_Task_Layout');
    ID OORTaskRecordTypeID = RecordTypeHelper.GetRecordTypeIdByDevName('Task', 'Local_Advertiser_Task');

    
    for(Task tsk :Trigger.New)  
    {
        if(tsk.RecordTypeId==CxGTaskRecordTypeID || tsk.RecordTypeId==OORTaskRecordTypeID)
           {        
               user_id.add(tsk.OwnerId); 
           }
    }
    if(user_id.size()>0)
    {
    Map<Id,User> usrs = New Map<Id,User>(); 
    for(User usr:[Select Name,ManagerId,Manager.FirstName,Manager.LastName,SFA_Office__c from User where Id IN: user_id ] ) 
      { 
          if(usr.ManagerId!=null)
          {   
              usrs.put(usr.Id,usr);
          }
      }
      If(usrs.Size()>0)
      {
      for(Task tsk :Trigger.New)  {
          
          tsk.SFA_Office_Code__c=usrs.get(tsk.OwnerId).SFA_Office__c;
          ID usrMgr= usrs.get(tsk.OwnerId).ManagerId;
          tsk.Owner_Manager__c=usrs.get(tsk.OwnerId).Manager.FirstName+''+usrs.get(tsk.OwnerId).Manager.LastName; 
       }
    }
  }
  
 }